package com.douqu.game.core.entity.world.map;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.EntityObject;
import com.douqu.game.core.protobuf.SGCommonProto;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: 城市掉落详情.
 * Description:
 * Date: 2018/7/14 0014 下午 5:22
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class CityDropData extends EntityObject {

    /** 所有玩家归属掉落 有且只有一个*/
    private CityDropBean allDrop;

    /** 阵营归属掉落 有且只有三个*/
    private Map<Integer,CityDropBean> campDropMap;

    /** 玩家归属掉落 不确定个数 用完就删除*/
    private Map<String,CityDropBean> playerDropMap = new ConcurrentHashMap<>();

    public CityDropBean getAllDrop() {
        return allDrop;
    }

    public CityDropData(){
        allDrop = new CityDropBean();
        campDropMap = new ConcurrentHashMap<>();
        campDropMap.put(SGCommonProto.E_CAMP_TYPE.CAMP_TYPE_BRIGHT_VALUE,new CityDropBean());
        campDropMap.put(SGCommonProto.E_CAMP_TYPE.CAMP_TYPE_BLOODY_VALUE,new CityDropBean());
        campDropMap.put(SGCommonProto.E_CAMP_TYPE.CAMP_TYPE_DARK_VALUE,new CityDropBean());
        playerDropMap = new ConcurrentHashMap<>();
    }

    public void loadFrom(ByteBuffer buffer){
        allDrop.loadFrom(buffer);
        int size = buffer.readByte();
        CityDropBean bean;
        for (int i = 0;i < size;i++){
            int key = buffer.readByte();
            bean = new CityDropBean();
            bean.loadFrom(buffer);
            campDropMap.put(key,bean);
        }
        size = buffer.readInt();
        String key;
        for (int i = 0;i < size;i++){
            key = buffer.readUTF();
            bean = new CityDropBean();
            bean.loadFrom(buffer);
            playerDropMap.put(key,bean);
        }
    }

    public void writeTo(ByteBuffer buffer){
        allDrop.writeTo(buffer);
        buffer.writeByte(campDropMap.size());
        for (Map.Entry<Integer,CityDropBean> entry:campDropMap.entrySet()){
            buffer.writeByte(entry.getKey());
            entry.getValue().writeTo(buffer);
        }
        buffer.writeInt(playerDropMap.size());
        for (Map.Entry<String,CityDropBean> entry:playerDropMap.entrySet()){
            buffer.writeUTF(entry.getKey());
            entry.getValue().writeTo(buffer);
        }
    }

    public void setAllDrop(CityDropBean allDrop) {
        this.allDrop = allDrop;
    }

    public Map<Integer, CityDropBean> getCampDropMap() {
        return campDropMap;
    }

    public void setCampDropMap(Map<Integer, CityDropBean> campDropMap) {
        this.campDropMap = campDropMap;
    }

    public Map<String, CityDropBean> getPlayerDropMap() {
        return playerDropMap;
    }

    public void setPlayerDropMap(Map<String, CityDropBean> playerDropMap) {
        this.playerDropMap = playerDropMap;
    }
}
